class Solution(object):
    def findRestaurant(self, list1, list2):
        """
        :type list1: List[str]
        :type list2: List[str]
        :rtype: List[str]
        """
        index_map= {name:i for i, name in enumerate(list1)}
        min_sum = float('inf') # 初始化一个无穷大的数
        res = []
        for j, name in enumerate(list2):
            if name in index_map:
                total_index = index_map[name] + j
                if total_index < min_sum:
                    min_sum = total_index
                    res = [name]
                elif total_index == min_sum:
                    res.append(name)
        return res

if __name__ == '__main__':
    list1 = ["Shogun", "Tapioca Express", "Burger King", "KFC"]
    list2 = ["Piatti", "The Grill at Torrey Pines", "Hungry Hunter Steakhouse", "Shogun"]
    print(Solution().findRestaurant(list1, list2))